package strategy_1.person;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;

/**
 * Created by zjh on 2017/9/13.
 */
public class Person {


    public static void main(String[] args) {
        Person person = new Person(22);
        List<Physique> physiques = person.analysisPhysique();//满足的体质
        if (physiques.size() > 1 || physiques.size() == 0) {
            System.out.println("判定无结果!");
        }else {
            System.out.println("判定体质为:" + physiques.get(0).physiqueName);
        }


    }

    //----------------------------------------------------------------------------

    //体质类型枚举
    EnumSet<Physique> physiqueEnumSet = EnumSet.allOf(Physique.class);
    //原始分
    Integer originalNum;

    public Person(Integer originalNum) {
        this.originalNum = originalNum;
    }

    /**
     * 判断是哪种体质
     */
    public List<Physique> analysisPhysique() {
        List<Physique> list = new ArrayList<Physique>();
        //1.计算所有的转化分
        for (Physique physique : physiqueEnumSet) {
            physique.calculate(originalNum);
        }

        //2.判断体质
        for (Physique physique : physiqueEnumSet) {
            if (physique.check()) {
                //System.out.println(physique.physiqueName);
                list.add(physique);
            }
        }
        return list;
    }

    //------------------------------------------------------------------------------
    //体质枚举
    public enum Physique {
        //平和质
        PinHe {
            public void calculate(Integer originalNum) {
                transformNum = Math.floor((((double) originalNum - 8) / (8 * 4)) * 100);
                physiqueName = "平和质";
                currentLimitNum = 60;
                othersLimitNum = 30;
            }
        },
        //阳虚质
        YangXu {
            public void calculate(Integer originalNum) {
                transformNum = Math.floor((((double)originalNum - 7) / (7 * 4)) * 100);
                physiqueName = "阳虚质";
                currentLimitNum = 40;
                othersLimitNum = 30;
            }
        },
        //阴虚质
        YinXu {
            public void calculate(Integer originalNum) {
                transformNum = Math.floor((((double)originalNum - 8) / (8 * 4)) * 100);
                physiqueName = "阴虚质";
                currentLimitNum = 40;
                othersLimitNum = 30;
            }
        },
        //气虚质
        QiXu {
            public void calculate(Integer originalNum) {
                transformNum = Math.floor((((double)originalNum - 8) / (8 * 4)) * 100);
                physiqueName = "气虚质";
                currentLimitNum = 40;
                othersLimitNum = 30;
            }
        },
        //湿热质
        ShiRe {
            public void calculate(Integer originalNum) {
                transformNum = Math.floor((((double)originalNum - 6) / (6 * 4)) * 100);
                physiqueName = "湿热质";
                currentLimitNum = 40;
                othersLimitNum = 30;
            }
        },
        //血淤质
        XueYu {
            public void calculate(Integer originalNum) {
                transformNum = Math.floor((((double)originalNum - 7) / (7 * 4)) * 100);
                physiqueName = "血淤质";
                currentLimitNum = 40;
                othersLimitNum = 30;
            }
        },
        //气淤质
        QiYu {
            public void calculate(Integer originalNum) {
                transformNum = Math.floor((((double)originalNum - 7) / (7 * 4)) * 100);
                physiqueName = "气淤质";
                currentLimitNum = 40;
                othersLimitNum = 30;
            }
        },
        //特禀质
        TeBing {
            public void calculate(Integer originalNum) {
                transformNum = Math.floor((((double)originalNum - 7) / (7 * 4)) * 100);
                physiqueName = "特禀质";
                currentLimitNum = 40;
                othersLimitNum = 30;
            }
        },
        ;

        //体质中文名称
        String physiqueName;
        //转化分
        double transformNum;
        //当前体质临界分
        Integer currentLimitNum;
        //其他体质临界分
        Integer othersLimitNum;

        public abstract void calculate(Integer originalNum);

        public boolean check() {
            System.out.println("------>判断是否满足:" + this.physiqueName);
            //条件1:当前体质转化分必须大于等于currentLimitNum
            boolean condition_1 = false;
            if (this.transformNum >= this.currentLimitNum) {
                System.out.println(
                        "满足:" + this.physiqueName + "转化分:" + this.transformNum + " >=" + this.currentLimitNum);
                condition_1 = true;
            }else {
                System.out.println(
                        "不满足:" + this.physiqueName + "转化分:" + this.transformNum + " <" + this.currentLimitNum);
                return condition_1;
            }

            boolean condition_2= true;
            Physique[] physiques = Physique.values();
            //条件2:所有其他体质转化分必须小于othersLimitNum分
            for (Physique other : physiques) {
                //有一个体质不满足小于othersLimitNum分则退出
                if(other != this && other.transformNum >= this.othersLimitNum) {
                    condition_2 = false;
                    System.out.println(
                            "不满足其他体质[" + other.physiqueName + "]判断条件:转化分<"
                                    + this.othersLimitNum + "------[" + other.physiqueName + "]转化分:" + other.transformNum
                                    + ">=" + this.othersLimitNum);
                    break;
                }
                System.out.println(
                        "满足其他体质[" + other.physiqueName + "]判断条件:转化分<"
                                + this.othersLimitNum + "------[" + other.physiqueName + "]转化分:" + other.transformNum
                                + "<" + this.othersLimitNum);
            }

            //以上两个条件都成立才返回true
            if (condition_1 && condition_2) {
                return true;
            }
            return false;
        }
    }

}
